<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                template="./../resources/Template.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml">

    <ui:define name="content">
        <link rel="stylesheet" type="text/css" href="../resources/css/style2.css" />      
        <h:outputStylesheet library="css" name="estilo.css" />
        <h:outputStylesheet library="css" name="tabela.css" />
        <h:outputScript library="js" name="javaScript.js" />
        <div class="header">
            Telas de Devolução
        </div>
        <p:separator />      
        <h:form id="frmSolDev">
            <p:growl />            
            <h:panelGrid columns="3" cellpadding="5">
                <h:outputLabel for="codAcervo" value="Código de Barras.:" styleClass="lb" />
                <h:inputText id="codAcervo" value="#{emprestimoBean.codAcervo}" styleClass="tx" converterMessage="Digite somente numeros">
                    <f:convertNumber type="number" />
                </h:inputText>
                <h:commandButton value="Devolução" actionListener="#{emprestimoBean.devolucaoCodigoBarras}" styleClass="btn" />
            </h:panelGrid>
        </h:form>
        <p:separator />
        <h:form id="frmConDev">         
            <h:inputHidden value="#{emprestimoBean.emprestimo.codEmprestimo}" />
            <h:panelGrid columns="4" cellpadding="5">
                <h:outputLabel for="acervo" value="Código.:" styleClass="lb" />
                <h:inputText id="acervo" value="#{emprestimoBean.emprestimo.acervo.codAcervo}" styleClass="tx" readonly="true" size="10" required="true" requiredMessage="Acervo Obrigatório"/>
                <h:outputLabel for="tit" value="Titulo.:" styleClass="lb" />
                <h:inputText id="tir" value="#{emprestimoBean.emprestimo.acervo.titulo.descricao}" styleClass="tx" readonly="true" size="60"/>
            </h:panelGrid>
            <h:panelGrid columns="4" cellpadding="5">
                <h:outputLabel for="dtEmprestimo" value="Data Emprestimo.:" styleClass="lb" />
                <h:inputText id="dtEmprestimo" value="#{emprestimoBean.emprestimo.dataEmprestimo}" styleClass="tx" readonly="true">
                    <f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
                </h:inputText>
                <h:outputLabel for="dtEntrega" value="Prev. Entrega.:" styleClass="lb" />
                <h:inputText id="dtEntrega" value="#{emprestimoBean.emprestimo.previsaoEntrega}" styleClass="tx" readonly="true">
                    <f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
                </h:inputText>
            </h:panelGrid>
            <h:panelGrid columns="4">
                <h:outputLabel for="dtDevolucao" value="Data Devolução.:" styleClass="lb" />
                <h:inputText id="dtDevolucao" value="#{emprestimoBean.emprestimo.dataDevolucao}" styleClass="tx" readonly="true">
                    <f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
                </h:inputText>                
                <h:commandButton value="Cancelar" actionListener="#{emprestimoBean.cancelar}" immediate="true" styleClass="btn" />
                <h:commandButton value="Confirmar" actionListener="#{emprestimoBean.confirmarDevolucao}" onclick="return confirmar('#{emprestimoBean.emprestimo.acervo.titulo.descricao}');" styleClass="btn" />
            </h:panelGrid>
        </h:form>
        <h:form id="frmTblDev" rendered="#{emprestimoBean.emprestimos.size() > 0}">
            <h:dataTable value="#{emprestimoBean.emprestimos}" var="e" styleClass="tabela" headerClass="cabecalho"
                         rowClasses="linA, linB" columnClasses="f_codigo, f_codigo, c_titulo, f_nasc, f_nasc, f_nasc, f_op">
                <h:column>
                    <f:facet name="header">Nº Emp.</f:facet>
                    <h:outputText value="#{e.codEmprestimo}" />
                </h:column>
                <h:column>
                    <f:facet name="header">Código</f:facet>
                    <h:outputText value="#{e.acervo.codAcervo}" />
                </h:column>
                <h:column>
                    <f:facet name="header">Titulo</f:facet>
                    <h:outputText value="#{e.acervo.titulo.descricao}" />
                </h:column>
                <h:column>
                    <f:facet name="header">DT Emp.</f:facet>
                    <h:outputText value="#{e.dataEmprestimo}">
                        <f:convertDateTime pattern="dd/MM/yyyy" />
                    </h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">Prev. Ent.</f:facet>
                    <h:outputText value="#{e.previsaoEntrega}">
                        <f:convertDateTime pattern="dd/MM/yyyy" />
                    </h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">DT Dev.</f:facet>
                    <h:outputText value="#{e.dataDevolucao}">
                        <f:convertDateTime pattern="dd/MM/yyyy" />
                    </h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">Op</f:facet>
                    <p:commandLink value="Devolver" action="#{emprestimoBean.devolver(e)}"  ajax="false" update="@form :frmConDev" styleClass="links" />
                </h:column>
            </h:dataTable>
        </h:form>
    </ui:define>
</ui:composition>
